import multiply_sim::*;

module tb();

   logic [7:0] sig[15:0];
// = {8'h12, 8'h34};
   

   //logic [16:0][8:0] pps_16;
   pps_16x16_t pps_16;
   pps_4x4_t pps_4;   
   

   logic signed [31:0] s_result;
   
   initial
     begin
	    #10;
	    //test_print();
	    
	    // $display("size of sig : %d", sig.size());



	begin
	   bit [3:0] a, b;
	   bit signed [8:0] correct_result;
	   
	   // for(int i=0;i<=255;i++)
	   //   begin
	   // 		a = i[3:0];
	   // 		b = i[7:4];
	   // 		correct_result = -(a*b);
	   // 		pps_4 = gen_4x4_pps(
	   // 							.i_a(a),
	   // 							.i_b(b),
	   // 							.i_sign(1'b0)
	   // 							);
	   // 		$display("-%d*%d = %d(%x): result = %d (%x)   =>  %s", a, b,correct_result, correct_result, 
	   // 				 $signed(pps_4.result), pps_4.result,
	   // 				 correct_result[7:0]==pps_4.result ? "equal" : "!!! Not Equal !!!"
	   // 				 );
	   //   end // for (int i=0;i<=255;i++)

	   a = 4'b0000;
	   b = 4'b1000;
	   pps_4 = gen_4x4_pps(
	   					   .i_a(a),
	   					   .i_b(b),
	   					   .i_sign(1'b0)
	   					   );
	   $display("-%d*%d = %d(%x): result = %d (%x)", a, b,correct_result, correct_result,
				$signed(pps_4.result), pps_4.result);

	   for(int i=0;i<3;i++)
		 $display("booth2_code[%d] : %d, PP[%d] = %d (%x)", 
				  i, pps_4.booth_array[i],
				  i, pps_4.pp[i], pps_4.pp[i]);
	   
	   
	end


		
		$finish;
	   
	s_result = $signed(4'ha) * $signed(4'h5);
	//$display("multiply : %d * %d = %d (%x)", $signed(4'ha), $signed(4'h5), s_result, s_result);

	// for(int i=0;i<8;i++)
	//   $display("pps_16_S[%d] = %d, pps_16_E[%d] = %d", i, pps_16.S[i], i, pps_16.E[i]);
	//$display("result = %d (%x)", $signed(pps_4.result), pps_4.result);

	$display("%d*%d = %d, result = %d (%x)", 4'ha, 4'h5, 4'ha*4'h5, $signed(pps_4.result), pps_4.result);
	
	$finish;
	



	    
	pps_16 = gen_16x16_pps(
			       .i_a(16'habcd),
			       .i_b(16'h5678),
			       .i_sign(1'b1)
			       );
	
	s_result = $signed(16'habcd) * $signed(16'h5678);
	$display("multiply : %d * %d = %d (%x)", $signed(16'habcd), $signed(16'h5678), s_result, s_result);
	for(int i=0;i<9;i++)
	  $display("pps_16[%d] = %x", i, pps_16.pp[i]);
	for(int i=0;i<8;i++)
	  $display("pps_16_S[%d] = %d, pps_16_E[%d] = %d", i, pps_16.S[i], i, pps_16.E[i]);
	$display("result = %d (%x)", $signed(pps_16.result), pps_16.result);

	for(int i=0;i<32;i++)
	  $display("cols_sum[%d] = %d", i, pps_16.cols_sum[i]);
	

	// begin
	//    int r, res;
	//    for(int i=0;i<10000;i++)
	//      begin
	// 	r = $random();
	// 	pps_16 = gen_16x16_pps(
	// 			       .i_a(r[31:16]),
	// 			       .i_b(r[15:0]),
	// 			       .i_sign(1'b1)
	// 			       );
	// 	res = $signed(r[31:16]) * $signed(r[15:0]);
	// 	if(pps_16.result == res)
	// 	  $display("equal %d", i);
	// 	else
	// 	  break;
	//      end // for (int i=0;i<10000;i++)
	// end
	
	
	
		
     end

endmodule // tb
